﻿@using BrnMall.Web.StoreAdmin.Models
@model EditIndexPictureWidgetCustomerFeaturesModel

@section header{
<title>小程序定制</title>
    <link type="text/css" rel="stylesheet" href="/admin_store/css/site.css"/>
    <script type="text/javascript" src="/admin_store/scripts/jquery.js"></script>
    <script type="text/javascript" src="/admin_store/scripts/jquery.validate.js"></script>
    <script type="text/javascript" src="/admin_store/scripts/jquery.validate.unobtrusive.js"></script>
    <link type="text/css" rel="stylesheet" href="/components/webuploader/webuploader.css"/>
    <script type="text/javascript" src="/components/webuploader/webuploader.js"></script>
    <link href="/components/jbox/Skins/Default/jbox.css" rel="stylesheet" type="text/css"/>
    <script type="text/javascript" src="/components/jbox/jquery.jBox-2.3.min.js"></script>
    <script type="text/javascript" src="/admin_store/scripts/showlist.js"></script>
    <script type="text/javascript" src="/components/my97datepicker/WdatePicker.js"></script>
    <script type="text/javascript" src="/admin_store/scripts/selectlist.js"></script>
    <script type="text/javascript">
        $(function () {
            var uploader = WebUploader.create({
                pick: '.uploadBut',
                auto: true,
                swf: '/components/webuploader/Uploader.swf',
                server: '/storeadmin/tool/upload?operation=uploadwidgetimage',
                fileVal: 'upload',
                accept: {
                    title: 'Images',
                    extensions: '@ViewData["allowImgType"]',
                    mimeTypes: '*'
                },
                fileSingleSizeLimit: @ViewData["maxImgSize"]
            });

            uploader.on('uploadProgress', function(file, percentage) {
                $(".uploadPreview").html("上传中...");
            });

            uploader.on('uploadSuccess', function(file, response) {
                var data = response._raw;
                if (data == "-1")
                    $(".uploadPreview").html('图片不能为空');
                else if (data == "-2")
                    $(".uploadPreview").html('图片类型不允许');
                else if (data == "-3")
                    $(".uploadPreview").html('图片太大');
                else {
                    $(".uploadPreview").html("<img src=\"@WorkContext.ImageCDN/upload/store/@WorkContext.StoreId/widget/" + data + "\"  />");
                    $("#ShowImg").val(data);
                }
            });

            uploader.on('uploadError', function(file) {
                $(".uploadPreview").html("上传失败");
            });
        });

    </script>

}

@section body{
    <h1 class="rightH1">
		微信小程序 &gt; <span class="rightH1-cur">小程序网站定制</span>
        <div class="right">
            <a href="@Html.Raw(ViewData["referer"].ToString())" class="menuBT">
                <img src="/admin_store/images/goback.jpg"/>返回列表</a>
            <div class="clear">
            </div>
        </div>
        <div class="clear">
        </div>
    </h1>
    <div class="table_top">
    </div>
    <div class="dataList">
        <table width="100%">
            <thead>
            <tr>

                <th width="80" align="left">
                    区域
                </th>
                
                <th width="140" align="left">
                    展示图片
                </th>
                <th width="120" align="center">
                    链接类型
                </th>
                <th align="center">
                    链接对象
                </th>
                <th width="60" align="left">
                    管理操作
                </th>
            </tr>
            </thead>
            <tbody>
            @foreach (LinkValue info in Model.CustomerFeatures)
            {
                <tr>

                    <td>@info.LinkArea
                    </td>
                    <td>
                        <img width="40" src="@WorkContext.ImageCDN/upload/store/@WorkContext.StoreId/widget/@info.ShowImg"/>
                    </td>
                    <td align="center">
                        @if (info.LinkType == "product")
                        {
                            <span class="mainimgspan">商品</span>
                        }
                        else if (info.LinkType == "store_class")
                        {
                            <span class="mainimgspan">店铺商品分类</span>
                        }
                        else if (info.LinkType == "news")
                        {
                            <span class="mainimgspan">内容</span>
                        }
                        else if (info.LinkType == "news_type")
                        {
                            <span class="mainimgspan">内容分类</span>
                        }
                        else if (info.LinkType == "page")
                        {
                            <span class="mainimgspan">关于我们</span>
                        }
                        else if (info.LinkType == "h5page")
                        {
                            <span class="mainimgspan">H5网页</span>
                        }
                        else if (info.LinkType == "phonecall")
                        {
                            <span class="mainimgspan">一键拨号</span>
                        }
                        else if (info.LinkType == "weappfunc")
                        {
                            <span class="mainimgspan">小程序功能</span>
                        }
                    </td>
                    <td align="center">
                        <span class="mainimgspan">@info.Name</span>
                    </td>
                    
                    <td>
                        <a href="#" url="@Url.Action("DeleteIndexPictureCustomerFeatures","pc", new { cid = Model.WidgetConfig.CId, itemIndex = Model.CustomerFeatures.IndexOf(info) })" class="editOperate ajaxdeleteOperate" }>删除</a>
                    </td>
                </tr>
            }
            </tbody>
        </table>
    </div>
    <div class="table_bottom bg">
    </div>
    @using (Html.BeginForm("AddIndexPictureCustomerFeatures", "pc"))
    {
        @Html.Hidden("CId",Model.WidgetConfig.CId)
        <div class="addTable" style="margin-left: 15px; margin-bottom: 10px; padding-top: 10px; border: 2px solid #dbeffa">
            <table width="100%">
                <tbody>
                <tr>
                    <td></td>
                    <td>
                        <img id="picDisplayType" src="@WorkContext.ImageCDN/images/weapp/widget/index_pic_@(Model.WidgetConfig.DisplayType+".jpg")" alt="" width="160px" />
                    </td>
                </tr>
                <tr>
                    <td></td>
                    <td>
                        @foreach (var tip in Model.UploadTips)
                        {
                            <div><span style="color:darkgrey">@tip</span></div>
                        }
                    </td>
                </tr>
                <tr>
                    <td width="66px"  align="right">图片区域：</td>
                    <td style="padding-left: 10px;">
                        @Html.DropDownList("LinkArea", Model.LinkArea.Select(t => new SelectListItem {Text = t, Value = t}), "请选择区域")
                    </td>
                </tr>
                
                <tr>
                    <td width="66px" align="right">展示图片：</td>
                    <td style="padding-left: 10px;">
                        <div class="upload">
                            <div class="uploadPreview">暂无图片</div>
                            <div class="left">
                                <div class="uploadProgressBar"></div>
                                <div class="uploadBut">选择图片</div>
                            </div>

                            <div class="clear"></div>
                            <div class="left"></div>
                        </div>
                        <input type="hidden" name="ShowImg" id="ShowImg" value=""/>
                    </td>
                </tr>
                <tr>
                    <td align="right">链接:</td>
                    <td style="padding-left: 10px;">
                        <div class="dataListSearch" style="padding-left: 0px;">
                            <table height="32">
                                <tbody>
                                <tr>
                                    <td>
                                        <select id="linktype" name="linktype">
                                            <option value="">选择分类</option>
                                            <option value="product">商品</option>
                                            <option value="store_class">店铺商品分类</option>
                                            <option value="news">内容</option>
                                            <option value="news_type">内容分类</option>
                                            <option value="page">页面</option>
                                            <option value="h5page">H5网页</option>
                                            @*<option value="phonecall">一键拨号</option>
                                            <option value="weappfunc">小程序功能</option>*@
                                        </select>
                                    </td>
                                    <td>
                                        <div class="selectBt selectBox" id="selectProduct" style="display: none">
                                            <input type="button" value="选择商品" onclick="openProductSelectLayer(this)" style="height: 22px; line-height: 22px; background: url(/admin_store/images/selectbgico.gif) no-repeat 6px center; padding-left: 22px; padding-right: 10px;">
                                            <input type="hidden" class="Pid" id="Pid" name="Pid" value=""/>
                                            <input type="hidden" class="ProductName" id="ProductName" name="ProductName" value=""/>
                                        </div>
                                        <div class="selectBt selectBox" id="selectStoreClass" style="display: none">
                                            @Html.DropDownList("StoreClassId", Model.StoreClassList.Select(t => new SelectListItem() {Selected = false, Text = t.Name, Value = t.StoreCid.ToString()}), "选择店铺分类")
                                        </div>

                                        <div class="selectBt" id="selectNewsType" style="display: none">
                                            @Html.DropDownList("NewsTypeId", Model.NewsTypeList.Select(t => new SelectListItem() {Selected = false, Text = t.Name, Value = t.NewsTypeId.ToString()}), "选择内容分类")
                                        </div>
                                        <div class="selectBt selectBox" id="selectNews" style="display: none">
                                            <input type="button" value="选择内容" onclick="openNewsSelectLayer(this)" style="height: 22px; line-height: 22px; background: url(/admin_store/images/selectbgico.gif) no-repeat 6px center; padding-left: 22px; padding-right: 10px;"/>
                                            <input type="hidden" class="NewsId" id="NewsId" name="NewsId" value=""/>
                                            <input type="hidden" class="NewsName" id="NewsName" name="NewsName" value=""/>
                                        </div>
                                        <div class="selectBt selectBox" id="selectPageInfo" style="display: none">
                                            <select id="PageInfoId" name="PageInfoId" class="valid">
                                                <option value="" selected>选择页面</option>
                                                <option value="2">关于我们</option>
                                            </select>
                                        </div>
                                        <div id="selectH5Page" class="selectBox" style="display: none">
                                            <input type="text" size="75" id="H5Page" name="H5Page" /><span>必须是https开头的网址</span>
                                        </div>
                                        <div id="selectPhoneCall" class="selectBox" style="display: none">
                                            <input type="text" size="20" id="PhoneNumber" name="PhoneNumber" />
                                        </div>
                                        <div class="selectBt selectBox" id="selectFunctionCode" style="display: none">
                                            @Html.DropDownList("FunctionCode", Model.FunctionCodes.Select(t => new SelectListItem() { Selected = false, Text = t.Name, Value = t.FunctionCode }), "选择小程序分类")
                                        </div>
                                    </td>
                                </tr>
                                </tbody>
                            </table>
                        </div>

                    </td>
                </tr>


                <tr>
                    <td align="right">
                    </td>
                    <td>
                        <input type="image" id="addImg" style="margin: 0px; padding: 0px;" src="/admin_store/images/a.jpg"/>
                        
                        <script type="text/javascript">
                            $("#addImg").click(function() {
                                if ($("#LinkArea").val() === "") {
                                    alert("请选择图片区域");
                                    return false;
                                }
                                if ($("#linktype").val() === "") {
                                    alert("链接不能为空");
                                    return false;
                                }
                                if ($("#ShowImg").val() == "") {
                                    alert("图片不能为空");
                                    return false;
                                } else {
                                    $(this).parents("form").submit();
                                    return false;
                                }
                            })

                            $("#linktype").change(function() {
                                console.log($(this).val());
                                var sel = $(this).val();

                                $(".selectBox").css("display", "none");
                                if (sel === "product") {
                                    $("#selectProduct").css("display", "block");
                                } else if (sel === "store_class") {
                                    $("#selectStoreClass").css("display", "block");
                                } else if (sel === "news") {
                                    $("#selectNews").css("display", "block");
                                } else if (sel === "news_type") {
                                    $("#selectNewsType").css("display", "block");
                                } else if (sel === "page") {
                                    $("#selectPageInfo").css("display", "block");
                                }else if (sel === "h5page") {
                                    $("#selectH5Page").css("display", "block");
                                }
                                else if (sel === "phonecall") {
                                    $("#selectPhoneCall").css("display", "block");
                                }
                                else if (sel === "weappfunc") {
                                    $("#selectFunctionCode").css("display", "block");
                                }

                            });
                        </script>
                    </td>
                </tr>
                </tbody>
            </table>
        </div>
    }
}